<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ include file="/taglibs.jsp"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="/css/ui.jqgrid.css" />
<link href="/css/ddaccordion.css" rel="stylesheet" type="text/css" media="screen" />
<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css"/>
<s:url var="supplierPops" value="/json/supplierPops.do"/>
<script language="javascript">
	var content;
	var qry_target = '01';
	$().ready( function() {
		$('#arrivalDate').datepick({minDate: '+1D', showOn: 'both',numberOfMonths:2,
	    	buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd",yearRange: '-1:+1'});
    	
		if ( "" == "${productIdParam}" )
			$("#productIdParam").val("可以用逗号输入商品编号查询").css("color","#aaa");
		
		$("#productIdParam").focus(function(){
			if($("#productIdParam").val()=='可以用逗号输入商品编号查询')
				$("#productIdParam").val("").css("color","#000");
			$("#productIdParam").attr('class','focus-ipt ipt-w20');
		}).blur(function(){
			if($("#productIdParam").val()=='')
				$("#productIdParam").val("可以用逗号输入商品编号查询").css("color","#aaa");
			$("#productIdParam").attr('class','ipt-w20');
		});
		 
		$("#supplierIdParam").numeric();
		$("#startStockQty").numeric();
		$("#endStockQty").numeric();
		$("#categoryIdParam").numeric();
		$("#getSupplier").click(function() {
			doAR('${supplierPops}', 'dialog'); 
			openDialog('供应商搜寻',content, 550, 440);
		});	
		if ( $("#stockNotify").attr("checked") ){
			$("#stockQty").show();
		}

		//load default value
		if ( "" != "${categoryLevel1Param}"){ 
			$("#categorySelect option[value='${categoryLevel1Param}']").attr('selected', 'selected');  
		}
		
		$("#stockNotify").click(function(){
			if ($(this).attr("checked")){
				$("#stockQty").show();
			}else{
				$("#stockQty").hide();
			}
		});

		$("#stockForm").submit(function(){
			if ( 0 == $(":checkbox[name='productIdBoxs']:checked").size() ){
				alert("请勾择设定预计到货日的商品");
				return false;
			} 
			if ( "" == $("#arrivalDate").val() ){
				alert("请输入预计到货日");
				return false;
			}
			return true;
		});
				
	});
	function replaceProductIdParam(){
		if($("#productIdParam").val()=='可以用逗号输入商品编号查询')
			$("#productIdParam").val("");
	}	
</script>
<h1>缺货报表</h1><br/>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<div class="data-form">
	<s:form action="stockOutReportSearch.do" method="post">
		<b>商品编号：</b>
		<input name="productIdParam" id="productIdParam" type="text" title="商品编号" size="80" value="${productIdParam}">
		<br/>
		<b>商品名称：</b>
		<input name="productNameParam" id="productNameParam" type="text" title="商品名称" size="30" value="${productNameParam}">
		<b>销售状态：</b> 
  	<s:select name="productStParam" list="attributeMenu.options" listKey="key"  headerKey="" headerValue="全部" listValue="value.name"/>
  	<br/>
		<b>供应商编号：</b>
		<s:textfield name="supplierParam" id="supplierIdParam" maxlength="6"/>
		<img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" 
			id="getSupplier"/>  	
		
		<b>主分类：</b>
	<select id="categorySelect" name="categoryLevel1Param">
			<option value="">--请选择--</option>
      	<c-rt:forEach items="${rootCategories}" var="category">
			<option value="${category.id}">${category.name}</option>
		</c-rt:forEach>
   </select>
		
		<b>分类：</b>
		<s:textfield name="categoryIdParam" id="categoryIdParam" maxlength="6"/>
		<br/>
		<b>主要负责PM：</b>
		<s:select id="pmIdParam" name="pmIdParam" list="users" listKey="username"  listValue="nameNative" headerKey="" headerValue="--请选择--"/>
		<br/>
	  <b><s:checkbox name="stockNotify" id="stockNotify"/>与补货通知关联</b>
	  <span id="stockQty" style="display:none;">
	  <b>缺货登记数量：</b>
	  <input name="startStockQty" id="startStockQty" type="text" size="5" maxlength="5" value="${startStockQty}" >~
	  <input name="endStockQty" id="endStockQty" type="text" size="5" maxlength="5" value="${endStockQty}" >
	  </span>
		<input type="button" value="查询" onclick="replaceProductIdParam();this.form.submit();" />
	</s:form>
</div>
<c-rt:if test="${not empty stockReports}">
<div class="f-link">
<a href="<c-rt:url value="/product2/stockOutReportExport.do"/>" >汇出缺货报表</a>
</div>
</c-rt:if>
<c-rt:choose>
	<c-rt:when test="${stockNotify}">
		<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th>#</th>
				<th>PM</th>
				<th>商品编号</th>
				<th>商品名称</th>
				<th>馆</th>
				<th>线</th>
				<th>其他分类</th>
				<th>缺货登记数</th>
				<th>供应商</th>
			</tr>
		</thead>
		<tbody>
		<c-rt:if test="${not empty stockReports}">
			<s:form action="stockOutReportSave.do" id="stockForm" method="post">
				<c-rt:forEach items="${stockReports}" var="stockReport" varStatus="index">
					<tr>
						<td><input type="checkbox" name="productIdBoxs" id="adb_${index.count}" value="${stockReport[1]}"/></td>
						<td>${stockReport[0]}</td>
						<td>${stockReport[1]}</td>
						<td>${stockReport[2]}</td>
						<td>${fn:split(stockReport[10],",")[0]}</td>
						<td>${fn:split(stockReport[10],",")[1]}</td>
						<td>
							<c-rt:forTokens begin="2" end="${fn:length(fn:split(stockReport[10],','))}" varStatus="i" delims="," items="${stockReport[10]}">
								${fn:split(stockReport[10],",")[i.index]}
								<c-rt:if test="${i.index < fn:length(fn:split(stockReport[10],','))-1}">/</c-rt:if>
							</c-rt:forTokens>
						</td>
						<td>登记数：${stockReport[5]}
							<c-rt:if test="${not empty stockReport[3]}">
								<br/>预计到货：<fmt-rt:formatDate value="${stockReport[3]}" pattern="yyyy-MM-dd"/>
							</c-rt:if> 
							<br/><a href="${midContextPath}/product2/spec.do?productId=${stockReport[1]}" target="_blank">编辑预计到货日</a>
						</td>
						<td>${stockReport[6]}</td>
					</tr>
				</c-rt:forEach>
			</s:form>
		</c-rt:if>
		<c-rt:if test="${empty stockReports}"><tr><td colspan="9">查无资料</td></tr></c-rt:if>
		</tbody>
	</table>
	<c-rt:if test="${not empty stockReports}">
		<input type="text" name="arrivalDate" id="arrivalDate" value="${arrivalDate}"/>
		<input type="submit" value="批次填写预计到货时间"/>
	</c-rt:if>
	</c-rt:when>
	<c-rt:otherwise>
		<table class="tb-1" width="100%">
			<thead>
				<tr>
					<th>PM</th>
					<th>商品编号</th>
					<th>商品名称</th>
					<th>规格ID</th>
					<th>规格名稱</th>
					<th>可售数</th>
					<th>已售数</th>
					<th>取消数</th>
					<th>商品状态</th>
					<th>分类ID</th>
					<th>规格状态</th>
				</tr>
			</thead>
			<tbody>
				<c-rt:if test="${not empty stockReports}">
					<c-rt:forEach items="${stockReports}" var="stockReport" varStatus="index">
						<tr>
							<td>${stockReport[0]}</td>
							<td>${stockReport[1]}</td>
							<td>${stockReport[2]}</td>
							<td>${stockReport[3]}</td>
							<td>${stockReport[4]}</td>
							<td>${stockReport[5]}</td>
							<td>${stockReport[6]}</td>
							<td>${stockReport[7]}</td>
							<td>${stockReport[8]}</td>
							<td>${stockReport[9]}</td>
							<td>${specSubStatusMenu.options[stockReport[10]].name}</td>
						</tr>
					</c-rt:forEach>
				</c-rt:if>
				<c-rt:if test="${empty stockReports}"><tr><td colspan="11">查无资料</td></tr>	</c-rt:if>
			</tbody>
		</table>	
	</c-rt:otherwise>
</c-rt:choose>

